home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / print / gs261sr1.zip / GDEVDJET.C < prev    next >
C/C++ Source or Header  |  1993-05-12  |  16KB  |  472 lines

  1. /* Copyright (C) 1989, 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* gdevdjet.c */
  20. /* HP LaserJet/DeskJet driver for Ghostscript */
  21. #include "gdevprn.h"
  22. #include "gdevpcl.h"
  23.  
  24. /*
  25.  * Thanks to Jim Mayer (mayer@wrc.xerox.com),
  26.  * Jan-Mark Wams (jms@cs.vu.nl), Frans van Hoesel (hoesel@rugr86.rug.nl),
  27.  * and George Cameron (g.cameron@biomed.abdn.ac.uk) for improvements.
  28.  */
  29.  
  30. /*
  31.  * You may select a resolution of 75, 100, 150, or 300 DPI.
  32.  * Normally you would do this in the makefile or on the gs command line,
  33.  * not here.
  34.  *
  35.  * If the preprocessor symbol A4 is defined, the default paper size is
  36.  * the European A4 size; otherwise it is the U.S. letter size (8.5"x11").
  37.  *
  38.  * You may find the following test page useful in determining the exact
  39.  * margin settings on your printer.  It prints four big arrows which
  40.  * point exactly to the for corners of an A4 sized paper. Of course the
  41.  * arrows cannot appear in full on the paper, and they are truncated by
  42.  * the margins. The margins measured on the testpage must match those
  43.  * in gdevdjet.c.  So the testpage indicates two facts: 1) the page is
  44.  * not printed in the right position 2) the page is truncated too much
  45.  * because the margins are wrong. Setting wrong margins in gdevdjet.c
  46.  * will also move the page, so both facts should be matched with the
  47.  * real world.
  48.  
  49. %!
  50.     newpath 
  51.     0 0 moveto 144 72 lineto 72 144 lineto
  52.     closepath fill stroke 0 0 moveto 144 144 lineto stroke
  53.  
  54.     595.27 841.88 moveto 451.27 769.88 lineto 523.27 697.88 lineto
  55.     closepath fill stroke 595.27 841.88 moveto 451.27 697.88 lineto stroke
  56.  
  57.     0 841.88 moveto 144 769.88 lineto 72 697.88 lineto
  58.     closepath fill stroke 0 841.88 moveto 144 697.88 lineto stroke
  59.  
  60.     595.27 0 moveto 451.27 72 lineto 523.27 144 lineto
  61.     closepath fill stroke 595.27 0 moveto 451.27 144 lineto stroke
  62.  
  63.     /Helvetica findfont
  64.     14 scalefont setfont
  65.     100 600 moveto
  66.     (This is an A4 testpage. The arrows should point exactly to the) show
  67.     100 580 moveto
  68.     (corners and the margins should match those given in gdev*.c) show
  69.     showpage
  70.  
  71.  */
  72. /*#define X_DPI 300*/
  73. /*#define Y_DPI 300*/
  74.  
  75. #define X_DPI_MAX 300
  76. #define Y_DPI_MAX 300
  77.  
  78. #ifndef X_DPI
  79. #  define X_DPI X_DPI_MAX
  80. #endif
  81. #ifndef Y_DPI
  82. #  define Y_DPI Y_DPI_MAX
  83. #endif
  84.  
  85. /*
  86.  * For all DeskJet Printers:
  87.  *
  88.  *  Maximum printing width               = 2400 dots = 8"
  89.  *  Maximum recommended printing height  = 3100 dots = 10 1/3"
  90.  *
  91.  * All Deskjets have 1/2" unprintable bottom margin.
  92.  * The recommendation comes from the HP Software Developer's Guide for
  93.  * the DeskJet 500, DeskJet PLUS, and DeskJet printers, version C.01.00
  94.  * of 12/1/90.
  95.  *
  96.  * Note that the margins defined just below here apply only to the DeskJet;
  97.  * the paper size, width and height apply to the LaserJet as well.
  98.  */
  99.  
  100. /* Margins are left, bottom, right, top. */
  101. /* from Frans van Hoesel hoesel@rugr86.rug.nl. */
  102. /* A4 has a left margin of 1/8 inch and at a printing width of
  103.  * 8 inch this give a right margin of 0.143. The 0.09 top margin is
  104.  * not the actual margin - which is 0.07 - but compensates for the
  105.  * inexact paperlength which is set to 117 10ths 
  106.  * Somebody should check for letter sized paper. I left it at 0.07
  107.  */
  108. #define DESKJET_MARGINS_LETTER  0.25, 0.50, 0.25, 0.07
  109. #define DESKJET_MARGINS_A4      0.125, 0.5, 0.143, 0.09
  110. /* Similar margins for the LaserJet, */
  111. /* from Eddy Andrews eeandrew@pyr.swan.ac.uk. */
  112. #define LASERJET_MARGINS_A4    0.25, 0.20, 0.25, 0.00
  113. #define LASERJET_MARGINS_LETTER    0.35, 0.20, 0.35, 0.00
  114.  
  115. #ifndef A4
  116. #  define DESKJET_MARGINS    DESKJET_MARGINS_LETTER
  117. #  define LASERJET_MARGINS    LASERJET_MARGINS_LETTER
  118. #else
  119. #  define DESKJET_MARGINS    DESKJET_MARGINS_A4
  120. #  define LASERJET_MARGINS    LASERJET_MARGINS_A4
  121. #endif
  122.  
  123. /* The number of blank lines that make it worthwhile to reposition */
  124. /* the cursor. */
  125. #define MIN_SKIP_LINES 7
  126.  
  127. /* We round up the LINE_SIZE to a multiple of a ulong for faster scanning. */
  128. #define W sizeof(word)
  129. #define LINE_SIZE ((X_DPI_MAX * 85 / 10 + W * 8 - 1) / (W * 8) * W)
  130.  
  131. /* Printer types */
  132. #define LJ    0
  133. #define LJplus    1
  134. #define LJ2p    2
  135. #define LJ3    3
  136. #define DJ    4
  137. #define DJ500    5
  138.  
  139. /*
  140.  * The notion that there is such a thing as a "PCL printer" is a fiction:
  141.  * no two "PCL" printers, even at the same PCL level, have compatible
  142.  * command sets.  The command strings below were established by hearsay
  143.  * and by trial and error.  (The H-P documentation isn't fully accurate
  144.  * either; for example, it doesn't reveal that the DeskJet printers
  145.  * implement anything beyond PCL 3.)
  146.  */
  147.  
  148. /* Printer capabilities */
  149. typedef enum {
  150.     mode_0,        /* PCL 3, use <ESC>*p+<n>Y for vertical spacing */
  151.     mode_2,        /* PCL 4, use <ESC>*b<n>Y for vertical spacing */
  152.     mode_2p,    /* PCL 4 but no vertical spacing */
  153.     mode_3        /* PCL 5, use <ESC>*b<n>Y and clear seed row */
  154.             /* (includes mode 2) */
  155. } compression_modes;
  156.  
  157. /* The printer initialization strings. */
  158. private const char *init_strings[] = {
  159.     /* LaserJet PCL 3, no compression */
  160.         "\033*p0x0Y\033*b0M",
  161.     /* LaserJet Plus PCL 3, no compression */
  162.         "\033*p0x0Y\033*b0M",
  163.     /* LaserJet IIP PCL 4, mode 2 compression */
  164.         "\033*r0F\033*p0x75Y\033*b2M",
  165.     /* LaserJet III PCL 5, mode 2&3 compression */
  166.         "\033*r0F\033*p0x75Y",
  167.     /* DeskJet almost PCL 4, mode 2 compression */
  168.         "\033&k1W\033*p0x0Y\033*b2M",
  169.     /* DeskJet 500 almost PCL 4, mode 2&3 compression */
  170.         "\033&k1W\033*p0x0Y",
  171. };
  172.  
  173. /* The device descriptors */
  174. private dev_proc_open_device(hpjet_open);
  175. private dev_proc_print_page(djet_print_page);
  176. private dev_proc_print_page(djet500_print_page);
  177. private dev_proc_print_page(ljet_print_page);
  178. private dev_proc_print_page(ljetplus_print_page);
  179. private dev_proc_print_page(ljet2p_print_page);
  180. private dev_proc_print_page(ljet3_print_page);
  181.  
  182. gx_device_procs prn_hp_procs =
  183.   prn_matrix_procs(hpjet_open, gdev_pcl_get_initial_matrix,
  184.     gdev_prn_output_page, gdev_prn_close);
  185.  
  186. gx_device_printer far_data gs_deskjet_device =
  187.   prn_device(prn_hp_procs, "deskjet",
  188.     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  189.     X_DPI, Y_DPI,
  190.     0, 0, 0, 0,        /* margins filled in by hpjet_open */
  191.     1, djet_print_page);
  192.  
  193. gx_device_printer far_data gs_djet500_device =
  194.   prn_device(prn_hp_procs, "djet500",
  195.     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  196.     X_DPI, Y_DPI,
  197.     0, 0, 0, 0,        /* margins filled in by hpjet_open */
  198.     1, djet500_print_page);
  199.  
  200. gx_device_printer far_data gs_laserjet_device =
  201.   prn_device(prn_hp_procs, "laserjet",
  202.     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  203.     X_DPI, Y_DPI,
  204.     0.05, 0.25, 0.55, 0.25,        /* margins */
  205.     1, ljet_print_page);
  206.  
  207. gx_device_printer far_data gs_ljetplus_device =
  208.   prn_device(prn_hp_procs, "ljetplus",
  209.     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  210.     X_DPI, Y_DPI,
  211.     0.05, 0.25, 0.55, 0.25,        /* margins */
  212.     1, ljetplus_print_page);
  213.  
  214. gx_device_printer far_data gs_ljet2p_device =
  215.   prn_device(prn_hp_procs, "ljet2p",
  216.     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  217.     X_DPI, Y_DPI,
  218.     0.20, 0.25, 0.25, 0.25,        /* margins */
  219.     1, ljet2p_print_page);
  220.  
  221. gx_device_printer far_data gs_ljet3_device =
  222.   prn_device(prn_hp_procs, "ljet3",
  223.     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  224.     X_DPI, Y_DPI,
  225.     0.20, 0.25, 0.25, 0.25,        /* margins */
  226.     1, ljet3_print_page);
  227.  
  228. /* Forward references */
  229. private int hpjet_print_page(P4(gx_devic